﻿@using SmartCode
@using SmartCode.Db
@model BuildContext
@{
    var project = Model.Project;
    var dbSource = Model.GetDataSource<DbSource>();
    var table = Model.GetCurrentTable();
    var pkCol = table.PKColumn;
    if (pkCol == null)
    {
        throw new SmartCodeException($"{table.Name} can not find PKColumn！");
    }
    var autoIncrement = table.AutoIncrement;
    var prefix = dbSource.DbProvider.ParameterPrefix;
    var notEqCols = table.Columns.Where(m => m.ConvertedName != m.Name);
    var resultMapName = $"{table.ConvertedName}ResultMap";
    var queryStatementResultMap = table.HasColNameNotEqConvertedName ? $"ResultMap=\"{resultMapName}\"" : "";
}

<!--获取数据列-->
<Statement Id="Query" @queryStatementResultMap>
    SELECT T.* From @table.Name T
    <Include RefId="QueryParams" />
    <Switch Prepend="Order By" Property="OrderBy">
        <Default>
            T.@pkCol.Name Desc
        </Default>
    </Switch>
    <IsNotEmpty Prepend="Limit" Property="Taken">@(prefix)Taken</IsNotEmpty>
</Statement>